package org.ktjy.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.ktjy.demo.entity.SysRight;
import org.ktjy.demo.entity.SysRoleRight;
import org.ktjy.demo.mapper.SysRightMapper;
import org.ktjy.demo.mapper.SysRoleRightMapper;
import org.ktjy.demo.service.ISysRoleRightService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lwj
 * @since 2024-03-07
 */
@Service
public class SysRoleRightServiceImpl extends ServiceImpl<SysRoleRightMapper, SysRoleRight> implements ISysRoleRightService {

    @Autowired
    SysRightMapper sysRightMapper;



    public void setSysRightMapper(SysRightMapper sysRightMapper) {
        this.sysRightMapper = sysRightMapper;
    }

    @Override
    public List<String> getRoleByRoleId(Long roleId) {
        QueryWrapper<SysRoleRight> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysRoleRight::getRfRoleId, roleId);
        List<SysRoleRight> tempList = list(queryWrapper);

        List<String> ids = new ArrayList<>();
        for (SysRoleRight temp : tempList) {
            ids.add(temp.getRfRightCode());
        }

        QueryWrapper<SysRight> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.lambda().in(SysRight::getRightCode, ids.toArray());
        List<SysRight> rightList = sysRightMapper.selectList(queryWrapper1);
        ids = new ArrayList<>();
        for (SysRight temp : rightList) {
            ids.add(temp.getRightCode());
        }
        return ids;
    }

    @Override
    public List<SysRight> getRightByUserRoleId(Long roleId) {
        QueryWrapper<SysRoleRight> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysRoleRight::getRfRoleId, roleId);
        List<SysRoleRight> tempList = list(queryWrapper);
        List<String> ids = new ArrayList<>();
        for (SysRoleRight temp:tempList){
            ids.add(temp.getRfRightCode());
        }
        QueryWrapper<SysRight> queryWrapper1=new QueryWrapper<>();
        queryWrapper1.lambda().in(SysRight::getRightCode,ids.toArray());
        List<SysRight> rightList=sysRightMapper.selectList(queryWrapper1);
        return rightList;
    }
}
